﻿using Aspose.Words;
using Aspose.Words.Saving;
using System.Data;

namespace ConsoleApp
{
    public class WordHelper
    {
        private static DataSet GetOneDs()
        {

            DataTable dt2 = new DataTable("Table");
            dt2.Columns.Add("name");
            dt2.Columns.Add("text");
            dt2.Columns.Add("money");

            dt2.Rows.Add(new object[] { "xw1", "1234567891", "6661" });
            dt2.Rows.Add(new object[] { "xw2", "1234567892", "6662" });
            dt2.Rows.Add(new object[] { "xw3", "1234567893", "6663" });

            DataSet ds = new DataSet();

            ds.Tables.Add(dt2);

            return ds;
        }

        public static void auto()
        {
            Document doc = new Document("d:/a/小程序合同.docx");

            var ds = GetOneDs();

            doc.MailMerge.ExecuteWithRegions(ds);
            doc.Save("d:/a/out/a.docx", SaveOptions.CreateSaveOptions(SaveFormat.Docx));
        }
    }
}